package tiled.util;

import java.io.File;
import java.io.IOException;

public class Util
{
    public static byte[] convertIntegersToBytes(int[] integers)
    {
        if (integers != null)
        {
            byte[] outputBytes = new byte[integers.length * 4];

            for (int i = 0, k = 0; i < integers.length; i++)
            {
                int integerTemp = integers[i];
                for (int j = 0; j < 4; j++, k++)
                {
                    outputBytes[k] = (byte)((integerTemp >> (8 * j)) & 0xFF);
                }
            }
            return outputBytes;
        }
        else
        {
            return null;
        }
    }

    public static boolean checkRoot(String filename)
    {
        File[] roots = File.listRoots();

        for (File root : roots)
        {
            try
            {
                String canonicalRoot = root.getCanonicalPath().toLowerCase();
                if (filename.toLowerCase().startsWith(canonicalRoot))
                {
                    return true;
                }
            }
            catch(IOException e)
            {       
            }
        }

        return false;
    }
}
